<script>
	import { checkLogin } from './libs/login';
	import { HTTP_REQUEST_URL } from './config/app';
	import Routine from './libs/routine.js';
	import {
		getopenid,wapplogin
	} from "@/api/api.js";
	export default {
		onLaunch: function(e)  {
			let that=this;
			const updateManager = uni.getUpdateManager();
			
			updateManager.onCheckForUpdate(function (res) {
			  // 请求完新版本信息的回调
			  console.log(res);
			  if(res.hasUpdate){
				uni.navigateTo({
					url:"/views/upload/index",
					fail(error) {
						console.log(error)
						uni.showToast({
							title:"跳转出错",
							icon:"none"
						})
					}
				})
			  }
			});
			if(e.query.scene){
				let scene=decodeURIComponent(e.query.scene);
				let theRequest = new Object();
				let strs = scene.split("&");
				for(let i = 0; i < strs.length; i++) {
				  theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
				}
				scene=theRequest;
				console.log(scene)
				if(scene.extend_uid){
					that.$Cache.set('extend_uid', scene.extend_uid, that.$Cache.time());
				}
			}
			if (HTTP_REQUEST_URL == '') {
				console.error(
					"请配置根目录下的config.js文件中的 'HTTP_REQUEST_URL'\n\n请修改开发者工具中【详情】->【AppID】改为自己的Appid\n\n请前往后台【小程序】->【小程序配置】填写自己的 appId and AppSecret"
				);
				return false;
			}
			uni.getSystemInfo({
			    success: function (res) {
			        that.$store.commit('SETSYSTEMINFO', res);
			    }
			});
			// #ifdef MP
			// 小程序静默授权
			console.log(this.$store.getters.isLogin, 'this.$store');
			if (!this.$store.getters.isLogin) {
				Routine.getCode()
					.then(code => {
						this.silenceAuth(code);
					})
					.catch(res => {
						uni.hideLoading();
					});
			}
			// #endif
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			// 小程序静默授权
			silenceAuth(code) {
				let that = this;
				getopenid(code).then(e=>{
					if(e.code==200){
						uni.setStorage({
							key: 'km_session_key',
							data: e.data.session_key,
						});
						that.getwapplogin(e.data.openid);
					}
				}).catch(res => {
					console.log(res)
				});
			},
			getwapplogin(openid){
				let that = this;
				let dt={
					"log_browser":this.$store.getters.systeminfo.model,
					"log_os":this.$store.getters.systeminfo.system
				};
				wapplogin(openid,JSON.stringify(dt)).then(res=>{
					that.$store.commit("LOGIN", {
						'token':res.data.token,
						'time':res.data.time - that.$Cache.time()
					});
					that.$store.commit("SETUID",res.data.uid);
				}).catch(res=>{
				})
			},
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "uview-ui/index.scss";
	.km_loading{
		display: flex;
		flex-direction: column;
		flex: 1;
		align-items: center;
		justify-content: center;
		position: fixed;
		top: 0;
		left:0;
		width: 100vw;
		height: 100vh;
		z-index: 99999;
		background-color:#FFFFFF ;
		image{
			height: 50px;
		}
	}
	page{
		font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Helvetica,
		Segoe UI, Arial, Roboto, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft Yahei',
		sans-serif;
		// color: #646566;
		color: #333;
		font-size: 28rpx;
	}
	.cardzdy{
	  padding: 20rpx 0;
	  background-color: #fff;
	  box-shadow: 0px 1px 9px 0px rgba(179,179,179,0.26);
	  border-radius: 12rpx;
	  overflow: hidden;
	  .zdytitle{
		 padding-top: 0rpx; 
	  }
	}
	.scroll-view_H{
	  white-space: nowrap;
	}
	.u-nav-slot {
		@include flex;
		align-items: center;
		justify-content: space-between;
		border-width: 0.5px;
		border: 1px solid #fff;
		border-radius: 100px;
		border-color: $u-border-color;
		padding: 3px 7px;
		opacity: 0.8;
	}
	.u-text-center{
		text-align: center;
	}
	.kmsection{
		padding: 20rpx;
		background-color: #FFFFFF;
		position: relative;
		.kmtitle{
			max-width: 80%;
			// padding-left:10rpx;
			// border-left: 5rpx solid #333333;
		}
		.kmsutitle{
			font-size: 24rpx;
			color: #999;
		}
		.kmtitle:before{
			content: "";
			padding-left:10rpx;
			border-left: 5rpx solid #333333;
		}
		.titleicon{
			position: absolute;
			right: 20px;
			top: 50%;
			margin-top: -15rpx;
		}
	}
	.margintop20{
		margin-top: 20rpx;
	}
	.margin-b40{
		margin-bottom: 40rpx;
	}
	.margin-b60{
		margin-bottom: 60rpx;
	}
	.margin-b20{
		margin-bottom: 20rpx;
	}
	.km_bg_white{
		background-color: #FFFFFF;
	}
	.km_fenge{
		display: inline-block;
		margin:0 10rpx ;
	}
	.km_font24{
		font-size: 24rpx;
	}
	.km_font26{
		font-size: 26rpx;
	}
	.km_font28{
		font-size: 28rpx;
	}
	.km_font30{
		font-size: 30rpx;
	}
	.km_float_right{
		float:right;
	}
	.km_viewcenter{
		width: 100%;
		height: 100%;
		/*flex 布局*/
		display: flex;
		/*实现垂直居中*/
		align-items: center;
		/*实现水平居中*/
		justify-content: center;
		
		text-align: justify;
	}
	// 非会员 模糊内容
	.novipbgmh{
		filter: blur(5px);
	}
	.novip{
		position: fixed;
		bottom: 0;
		left:0;
		height: calc(100vh - 20px - 90rpx - 90rpx);
		width: 100vw;
		overflow: auto;
		.noviptop{
			padding: 20rpx 0;
			text-align: center;
			.title{
				font-size: 35rpx;
				color:  #fa3534;
				.number{
					font-size: 50rpx;
				}
			}
			.subtitle{
				font-size: 32rpx;
				color: #666;
				margin: 10rpx 0;
			}
			.btn_1{
				margin-top: 20rpx;
				.btn_2{
					width: 500rpx;
					line-height: 80rpx;
					color: #fff;
					background-color: #fa3534;
					margin: 0 auto;
					border-radius: 120rpx;
				}
			}
		}
		.novipcenter{
			width: 100vw;
			min-height: 100rpx;
			height: auto;
			position: relative;
			margin-top: 20rpx;
			.tequan{
				width: 100%;
			}
			.btn_1{
				position: absolute;
				bottom: 20rpx;
				left: 0;
				width: 100%;
				.btn_2{
					width: 80%;
					line-height: 80rpx;
					margin: 0 auto;
					background-color: #fa3534;
					color: #fff;
					border-radius:120rpx;
					text-align: center;
				}
			}
		}
	}
	.userOffLine{
		-webkit-filter: grayscale(100%);
		/* Chrome, Safari, Opera */
		filter: grayscale(100%);
	}
</style>
